<template>
  <div class="toprecord other_common">
    <table class="common">
      <tbody>
        <tr>
          <td width="10%" class="tableleft">用户id</td>
          <td>
            <input type="text" id="Id" v-model="inId" @blur="ssmis(inId)" />
            <span style="color:#777">
              <span ref="infoSpan" id="info" style="color:red"></span>
            </span>
          </td>
        </tr>
        <tr>
          <td class="tableleft">加款金额:</td>
          <td>
            <input type="text" id="Money" v-model="pay_money" />
          </td>
        </tr>
        <tr>
          <td class="tableleft">备注:</td>
          <td>
            <input type="text" id="content" v-model="content" />
          </td>
        </tr>
        <tr>
          <td class="tableleft"></td>
          <td>
            <button
              class="btn btn-primary"
              id="subnit"
              @click="
                upperscore(
                  account
                    ? account.status == false
                      ? ''
                      : account.list.account_id
                    : '',
                  pay_money,
                  content
                )
              "
            >
              保存
            </button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import http from "@/utils/http";
import { Toast } from "vant";
export default {
  data() {
    return {
      inId: "",
      pay_money: "",
      content: "",
      account: ""
    };
  },
  computed: {},
  methods: {
    // 保存
    upperscore(id, money, remarks) {
      let infoSpan = this.$refs.infoSpan;
      if (id == "") {
        Toast("请输入正确用户ID");
      } else if (id != "" && money == "") {
        Toast("请输入加款金额");
      } else {
        this.inId = "";
        this.pay_money = "";
        this.content = "";
        infoSpan.innerText = "";
        http
          .post(
            `/api/login/add_balance/manually?account_id=${id}&pay_money=${money}&remarks=${remarks}&token=2Q3ntNqyo5eaLmXITABb`
          )
          .then(response => {
            // console.log(response);
            if (response) {
              let res = response.data;
              Toast(res);
            }
          });
      }
    },
    // 表单验证
    ssmis(id) {
      let infoSpan = this.$refs.infoSpan;
      // console.log(id)
      if (id) {
        http
          .post(
            `/api/login/room_user/fornull?account_id=${id}&token=2Q3ntNqyo5eaLmXITABb`
          )
          .then(response => {
            console.log(response);
            if (response) {
              let res = response.data;
              this.account = res;
              if (this.account.status == true) {
                infoSpan.innerText =
                  "昵称:" +
                  this.account.list.nickname +
                  "余额:" +
                  this.account.list.balance;
              } else {
                console.log(12);
                infoSpan.innerText = this.account.msg;
              }
            }
          });
      } else {
        infoSpan.innerText = "";
        this.account = "";
      }
    }
  }
};
</script>

<style>
.toprecord {
  padding-top: 10px;
}
</style>
